package com.x.epspace.message.client;


import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.x.epspace.common.AppConfig;
import com.x.epspace.message.sms.SmsPortType;
import com.x.epspace.message.sms.Sms_Service;

@Component("messageSender")
public class MessageSender {
	
	private static final Log log = LogFactory.getLog(MessageSender.class);
	
	public Map<String,String> sendMessage(String phonenumber, String contend) {
		Map<String,String> reMap = new HashMap<String,String>(2);
		try{
			Sms_Service sms_Service=new Sms_Service();
			SmsPortType  smsPortType=sms_Service.getSmsHttpPort();
			String reString = smsPortType.sms(MessageConfig.getCode_cu(), MessageConfig.getUsername_cu(), MessageConfig.getPassword_cu(), contend, phonenumber, "", "", "", "", "", "");
			log.info("reString="+reString);
			String[] reStrs = reString.split("&");
			if(reStrs[0].split("=")[1].equals("0")){
				reMap.put("result", AppConfig.getProperty("success", "return_code"));
			}else{
				reMap.put("result", AppConfig.getProperty("fail", "return_code"));
			}
			reMap.put("description", reStrs[1].split("=")[1]);
			return reMap;
		}catch(Exception e){
			e.printStackTrace();
			reMap.put("result",AppConfig.getProperty("fail", "return_code"));
			reMap.put("description","发送短信产生错误");
			return reMap;
		}
	}
	
	public static void main(String[] args){
		//MessageSender sender = new MessageSender();
		//sender.sendMessage("18971157011", "测试3");
		String reString = "result=0&description=发送短信成功&taskid=20260971761&faillist=&task_id=20260971761";
		String[] reStrs = reString.split("&");
		System.out.println(reStrs[0].split("=")[1]);
		System.out.println(reStrs[1].split("=")[1]);
		
	}
	
}
